//
//  AFNetworkManager.swift
//  MyNews
//
//  Created by DF-Mac on 16/12/7.
//  Copyright © 2016年 DF-Mac. All rights reserved.
//

import UIKit
import AFNetworking


enum HTTPMethod {
    case GET
    case POST
}
class AFNetworkManager: AFHTTPSessionManager {
    //单例
    static let shared = AFNetworkManager()
    
    func request(method:HTTPMethod = .GET,URLString:String,parameters:[String:Any],completion:@escaping ( _ json:Any?, _ isSuccess:Bool) -> Void) {
        let success = {
            (task:URLSessionDataTask,json:Any? ) -> Void in
            
            completion(json,true)
        }
        
        let failure = {
            (task:URLSessionDataTask?,error:Error) -> Void in
            
            print("网络请求错误:\(error)")
            
            completion(nil, false)
            
        }
        
        if method == .GET {
            
            get(URLString, parameters: parameters, progress: nil, success: success, failure: failure)
        }else{
            post(URLString, parameters: parameters, progress: nil, success: success, failure: failure)
        }
        
        
    }
}
